package com.newsvoice.activity;

/**
 * @author Paresh N. Mayani
 * http://www.technotalkative.com
 */

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public abstract class DashBoardActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	public void setHeader(String title, boolean btnBackVisible,
			boolean btnHomeVisible, boolean btnRefreshVisible, boolean btnShareVisible) {
		ViewStub stub = (ViewStub) findViewById(R.id.vsHeader);
		View inflated = stub.inflate();

		TextView txtTitle = (TextView) inflated.findViewById(R.id.txtHeading);
		txtTitle.setText(title);
		Button btnBack = (Button) inflated.findViewById(R.id.btnBack);
		if (!btnBackVisible) {
			((LinearLayout) btnBack.getParent()).removeView(btnBack);
		}
		Button btnHome = (Button) inflated.findViewById(R.id.btnHome);
		if (!btnHomeVisible)
			((LinearLayout) btnHome.getParent()).removeView(btnHome);		
		Button btnShare = (Button) inflated.findViewById(R.id.btnShare);
		if (!btnShareVisible)
			((LinearLayout) btnShare.getParent()).removeView(btnShare);
		
		Button btnRefresh = (Button) inflated.findViewById(R.id.btnRefresh);
		if (!btnRefreshVisible)
			((LinearLayout) btnRefresh.getParent()).removeView(btnRefresh);
			
//		Button btnFeedback = (Button) inflated.findViewById(R.id.btnFeedback);
//		if (!btnFeedbackVisible)
//			btnFeedback.setVisibility(View.INVISIBLE);

	}

	/**
	 * Home button click handler
	 * 
	 * @param v
	 */
	public void btnHomeClick(View v) {
		Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(intent);

	}

	/**
	 * Back button click handler
	 * 
	 * @param v
	 */
	public void btnBackClick(View v) {
		onBackPressed();
	}
	
	public void btnRefreshClick(View v) {
		
	}

	public void btnShareClick(View v) {
		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("text/plain");
		intent.putExtra(Intent.EXTRA_TEXT, "http://www.techrepublic.com");
		intent.putExtra(Intent.EXTRA_TITLE, "check out");
		intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
				"Check out this site!");
		startActivity(Intent.createChooser(intent, "Share"));
	}

	/**
	 * Feedback button click handler
	 * 
	 * @param v
	 */
	public void btnFeedbackClick(View v) {
		Intent intent = new Intent(getApplicationContext(),
				FeedbackActivity.class);
		startActivity(intent);
	}
}